<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.controller');

class SchedulersController extends JController
{
	private $scheduler_log = false;

	function __construct() {
		parent::__construct();
		$this->registerTask( 'save' , 'save' );
		$this->registerTask( 'cancel' , 'cancel' );
		$config =& JFactory::getConfig();
		if ($config->_registry['config']['data']->scheduler_log == true) {
			$this->scheduler_log = true;
		}
	}


	function save() {
		$model = $this->getModel('schedulers');
		$data_post = JRequest::get( 'post' );
		foreach ($data_post as $k => $v) {
			if (substr($k, 0, 4) == 'cfg_') {
				$data['name'] = substr($k, 4);
				$data['value'] = $v;
				$model->store($data);
				}
		if ($this->scheduler_log == true)
			error_log("SchedulersController saving\r\ndata = ".print_r($data, true)."\r\n\r\n", 3, JPATH_ROOT."/scheduler.log");
		}

		$link = 'index.php?option=com_scheduler';
		$this->setRedirect($link);
	}
	
	function cancel() {
		$this->setRedirect( 'index.php');
	}


}